package dreamCookGame;

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.image.BufferedImage;

public class Button {

	int _x;
	int _y;
	public Shape _boundingBox;
	String[] _stateImgNames;
	BufferedImage[][] _states;
	int _state;
	BufferedImage _img;
	boolean _changed;
	
	
	public Button(int x, int y, Shape boundingBox, String[] stateImgNames) {
		_x = x;
		_y = y;
		_boundingBox = boundingBox;
		_states = new BufferedImage[stateImgNames.length][2];
		_stateImgNames = stateImgNames;
		_state = 0;
	}
	
	public void loadResources(References reference) {
		for(int i = 0; i < _states.length; i++)
			_states[i]  = reference.getImageArray(_stateImgNames[i]);
		_img = _states[0][0];
	}
	

	public void changeState(int state) {
		_state = state;
		_img = _states[state][0];
		_changed = true;
	}
	
	public void highlight() {
		
		if(_states[_state].length > 1) {
			_img = _states[_state][1];
		}
			_changed = true;

	}

	public void unHighlight() {
		_img = _states[_state][0];
		_changed = true;
	}
	
	public boolean checkIfOnButton(Point point) {
		if(_boundingBox.contains(point))
			return true;
		else
			return false;
	}
	
	public void updatePositionRectangle(int x, int y) {
		//WARNING!! only use this method if you're sure that your bounding box is a rectangle!!
		_x = x;
		_y = y;
		Rectangle rectangle = _boundingBox.getBounds();
		Rectangle newBoundingBox = new Rectangle(x, y, rectangle.width, rectangle.height);
		_boundingBox = newBoundingBox;
	}

	public void shift(int dx, int dy) {
		_x += dx;
		_y += dy;
	}
}
